// components/val_input/val_input.js
Component({

  properties: {
    min: {
      type: Number,
      value: 0,
      observer: function (val) {
        this.setData({
          min: val,
        });
      },
    },
    value: {
      type: Number,
      observer: function (val) {
        console.log('prop val:', val);
        this.setData({
          val: val,
        });
      },
    },
    step: {
      type: Number,
      value: 1,
      observer: function (val) {
        this.setData({
          step: val,
        });
      },
    },
  },
  data: {
    min: 0,
    val: 0,
    step: 1,
  },
  methods: {
    onDecrease: function () {
      var val = this.data.value - this.data.step;
      this.syncValue(val);
    },
    onIncrease: function () {
      var val = this.data.value + this.data.step;
      this.syncValue(val);
    },
    onInput: function (e) {
      var value = e.detail.value;
      this.syncValue(value);
    },
    syncValue: function (val) {
      if (val < this.data.min) {
        val = this.data.min
      }
      this.setData({
        val: val,
      });
      this.triggerEvent('input', {
        value: val
      });
    },
  },
});